// handleSave.js

import axios from "axios";
import { ElMessage, ElMessageBox, ElNotification } from "element-plus";

export default function (data) {
  return new Promise((resolve, reject) => {
    axios
      .post("api/journal_diversion_share.php", {
        action: "save",
        data,
      })
      .then((response) => {
        console.log("DiversionShare->handleSave", data, response.data);
        if (response.data.result) {
          ElNotification({
            type: "success",
            title: "已保存",
          });
          resolve(response.data);
        } else {
          ElNotification({
            type: "warning",
            title: "保存出错了",
            message: response.data.sql,
          });
          reject(response.data);
        }
      })
      .catch((error) => {
        ElNotification({
          type: "error",
          title: "保存出错了",
          message: JSON.stringify(error, null, 2),
        });
        reject(error);
      });
  });
}
